<%= tr8n_with_options_tag(:default_locale => Tr8n::Config.default_admin_locale, :admin => true) do %>
	<%= render :partial => "/tr8n/common/header" %>
	<%= render :partial => "breadcrumb" %>
	
  <div class="section blue">
	  <%= form_tag({:action => :index}, {:method => :get, :id => "translations_search_form"}) do %>
	      <%=hidden_field_tag(:section_key, @section_key) %>
	      <%=hidden_field_tag(:source_id, params[:source_id]) %>
	      <%=hidden_field_tag(:component_id, params[:component_id]) %>
	      <%=hidden_field_tag(:sources, params[:sources]) %>
			  <div class="tr8n_fltr">
	        <button type="submit" class="translator_btn translator_small_btn" onClick="Tr8n.Effects.submit('translations_search_form'); return false;">
	            <span><%=tra("Search")%></span>
	        </button>
			  </div>
				
	    	<div class="tr8n_txtl">
	    		<%=text_field_tag(:search, params[:search], {:style => "width:90%;font-size:12px;height:20px;background: white url(/assets/tr8n/icn_search.png) right no-repeat; padding-right: 20px; border-radius:10px;", :placeholder => trla("Search phrases")})%>
	    	</div>

				<div class="tr8n_txtl" style="margin-top:10px; padding:3px; font-size:11px; color:#666; font-weight:bold;">
	          <%=tra("Search phrases")%>
	          <%=select_tag(:phrase_type, tr8n_options_for_select(Tr8n::TranslationKey.filter_phrase_type_options, params[:phrase_type]), :onChange => "toggleFilterOptions()")%>
	          <span id="extended_filter_options" style="<%='display:none' unless params[:phrase_type]=="with" %>">
	            <%=tra("marked as", "Phrases marked as some status")%>
	            <%=select_tag(:phrase_status, tr8n_options_for_select(Tr8n::TranslationKey.filter_phrase_status_options, params[:phrase_status]))%>
	          </span>
						<%=tra("include", "Phrases that include some information")%>
						<%=select_tag(:phrase_lock, tr8n_options_for_select(Tr8n::TranslationKey.filter_phrase_lock_options, params[:phrase_lock]))%>
	      </div>
									
	  <% end %>
	</div>
	
	<div class="section">
  	<%= tr8n_paginator_tag(@translation_keys, :subject => 'phrase') if @translation_keys.any? %>	
	
	  <table style="width:100%">
	    <tr style="border-bottom:2px solid #ccc;">
	       <td class="tr8n_txtl" style="width:30%;padding:5px; background: #f9f8f7; font-size:16px; color:grey;">
				   <%=tra("Original Phrase")%>
				 </td>
	       <td class="tr8n_txtl" style="width:70%;padding:5px; font-size:16px; color:grey;" colspan="2">
				   <%=tra("Top {language} Translations", nil, :language => tr8n_current_language.native_name) %>
				 </td>
	    </tr>  
	    <% @translation_keys.each do |tk| %>
	      <tr style="border-bottom:1px dotted #ccc;">

	        <% color = tk.locked? ? "#ECFFEF" : "#FDFDDF" %>
	        <td class="tr8n_txtl" style="padding:5px; background: <%=color%>;">
	          <% if tk.locked? %>
	            <div class="tr8n_fltr"><%=image_tag("tr8n/lock.png", :style=>"width:12px", :title => trla("This phrase is locked"))%></div>
	          <% end %>
	          <span dir='ltr'>
	          	<%=link_to(tk.default_decoration, :action => :view, :translation_key_id => tk.id, :section_key => @section_key)%>
	        	</span>
	          <div class="tr8n_txtl" dir='ltr' style="color:grey;font-size:10px;padding-top:3px;"><%=tk.description%></div>
	        </td>

	        <td style="padding:5px; vertical-align:top">
	          <div id="tr8n_translator_votes_for_<%=tk.key%>" class="tr8n_txtl">
	          <% translations = tk.translations_for(tr8n_current_language) %>
				    <% if translations.empty? %>
	            <%= tra("There are no translations for this phrase.") %> 

							<% unless tk.locked? %>
		            <%= tra("Be the first one to [link: translate it].", nil, :link => lambda{|str| link_to(str, :controller => "/tr8n/phrases", :action => :view, :translation_key_id => tk.id, :section_key => @section_key)}  ) %>
							<% end %>				

				    <% else %>   
	            <%= render :partial => "/tr8n/common/translation_votes", :locals => {:translation_key => tk, :translations => translations[0..4], :section_key => @section_key} %>
						<% end %>	
	          </div>  
	        </td>

	      </tr>
	    <% end %>
	  </table>
	  
		<% if @translation_keys.empty? %>
		    <div class="tr8n_txtl" style="padding-top:10px; font-size:12px;"><%=trla("No phrases found")%></div>
		<% end %>
		
  	<%= tr8n_paginator_tag(@translation_keys, :subject => 'phrase') if @translation_keys.any? %>	
	</div>
	<%= render :partial => "/tr8n/common/footer" %>
	
	<script>
	  function toggleFilterOptions() {
	    if (Tr8n.element("phrase_type").value == "with") {
	      Tr8n.Effects.show("extended_filter_options");
	    } else {
	      Tr8n.Effects.hide("extended_filter_options");
	    }
	  }
	</script>
<% end %>